package cn.kattomy.shop.interceptor;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;

import cn.kattomy.shop.adminuser.vo.AdminUser;

/**
 * 后台权限校验的拦截器
 * 对没有登录的用户，不可进行访问的
 * @author kattomy
 *
 */
public class PrivilegeInterceptor extends MethodFilterInterceptor {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	//执行拦截的方法
	@Override
	protected String doIntercept(ActionInvocation actionInvocation) throws Exception {
		//判断 session 中是否保存了后台用户的信息
		AdminUser existAdminUser = (AdminUser) ServletActionContext.getRequest().getSession().getAttribute("existAdminUser");
		if (existAdminUser == null) {
			//没有登录进行访问
			ActionSupport actionSupport = (ActionSupport) actionInvocation.getAction();
			actionSupport.addActionError("登录以获取访问权限");
			return "loginFail";
		}else {
			//已经登录过了
			return actionInvocation.invoke();
		}
	}
	
}
